<template>
    
    <div>
      <zh-form ref="formRef" :md="24" :lg="24" :xl="24"  :model="AuthVerifyInfo" :rules="rules" labelWidth="120">
        <zh-form-select
            prop="appId"
            :lazy="true"
            label="所属应用"
            v-model="AuthVerifyInfo.appId"
            :fieldNames="{ label: 'appName', value: 'appId' }"
            funcCode="application0012"
            :disabled="true"
            searchField="appName"
        ></zh-form-select>
        <zh-form-input prop="fileClassCode" label="文件分类编码"  v-model="AuthVerifyInfo.fileClassCode"
                       disabled></zh-form-input>
        <zh-form-input prop="fileClassTitle" label="文件分类"  v-model="AuthVerifyInfo.fileClassTitle"
                       disabled></zh-form-input>
        <zh-form-input prop="fileClassPath" label="存放基础路径"  v-model="AuthVerifyInfo.fileClassPath"
                       :disabled="true"></zh-form-input>
        <zh-form-input type="datetime" prop="expireTime" label="到期时间"  v-model="AuthVerifyInfo.expireTime"
                       :disabled="true"></zh-form-input>
        <zh-form-input type="textarea" prop="auditOpinion" label="审核意见"  v-model="AuthVerifyInfo.auditOpinion"
        :disabled="false"></zh-form-input>
      </zh-form>
    </div>
</template>

<script lang="ts" setup name="authVerifyWriteInfo">
import {FormInstance} from "element-plus";
import ZhForm from "@/components/zh-form/index.vue";
import { ElMessage } from 'element-plus';

// ------------------变量区------------------------------
const props = defineProps({
    AuthVerifyWriteParam: {
        type: Object,
        default: () => { },
        required: false,
    },
    showFlag: {
        type: Boolean,
        default: false
    },
    modelValue: Boolean,
});

const formRef = ref<FormInstance>();
const AuthVerifyInfo = ref<any>({
});
const emit = defineEmits(['update:modelValue']);

const rules = reactive({
  appId: [
    {
      required: true,
      message: '请选择需要授权的应用',
      trigger: 'blur',
    },
  ],
  auditOpinion: [
    {
      required: true,
      message: '请输入审核意见',
      trigger: 'blur',
    },
  ],
});


//------------------初始化------------------------------
onMounted(() => {
    
    init();
})

//--------------------------定义调用方法--------------------------------------------------
function init(){
    formRef.value?.resetFields();
    AuthVerifyInfo.value=props.AuthVerifyWriteParam; 

}

async function savePass() {
    if (!AuthVerifyInfo.value || !AuthVerifyInfo.value.appClassId) {
        ElMessage.success('待审核数据为空！');
        return
    } else {        
        const info = AuthVerifyInfo.value;
        info.authStatus='1';    
        let ret = { saveType: '', code: 0 };           
        ret = await $api.common.fileSend.post('fileAppClass0005', info);
        ret.saveType = 'edit';
        if (ret.code === 0) {
            ElMessage.success('审核成功！');
            emit('update:modelValue', false);
        }       
    }     
    return null;
}

async function saveNoPass() {
    if (!AuthVerifyInfo.value || !AuthVerifyInfo.value.appClassId) {
        ElMessage.success('待审核数据为空！');
        return
    } else {        
        const info = AuthVerifyInfo.value;
        info.authStatus='2';    
        let ret = { saveType: '', code: 0 };           
        ret = await $api.common.fileSend.post('fileAppClass0005', info);
        ret.saveType = 'edit';
        if (ret.code === 0) {
            ElMessage.success('审核成功！');
            emit('update:modelValue', false);
        }       
    }     
    return null;
}

//------------设置给父组件调用的数据/方法(组件)-----------
defineExpose({savePass,saveNoPass,AuthVerifyInfo});
</script>
